package time.after.time.web.pro;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import time.after.time.entity.account.User;
import time.after.time.entity.pro.City;
import time.after.time.service.account.AccountManager;
import time.after.time.service.pro.CityManager;
import time.after.time.sys.utils.Mapper;
import time.after.time.sys.utils.Result;
import time.after.time.web.BaseActionSupport;

/**
 * 
 * @author HuMing create in 2013-3-28
 */

public class IndexAction extends BaseActionSupport 
{

	private static final long serialVersionUID = 1L;

	@Autowired
	private CityManager cityManager;
	
	private String cityJson;
	
	@Autowired
	private AccountManager accountManager;
	
	private User user;
	
	private int autoReceive;
	
	@Override
	public String execute() 
	{
		List<City> citys=cityManager.getCitys();
		cityJson=Mapper.writeValueAsString(citys,"");
		user=getCurrentUser();
		return SUCCESS;
	}
	
	public void autoReceive()
	{
		user=getCurrentUser();
		user.setAutoReceive(autoReceive);
		accountManager.saveUser(user);
		Struts2Utils.renderJson(new Result(200, "ok"));
	}

	public String getCityJson() {
		return cityJson;
	}

	public User getUser() {
		return user;
	}

	public void setAutoReceive(int autoReceive) {
		this.autoReceive = autoReceive;
	}
	
}
